package com.sky.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderDetailVO;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
* @author luo20
* @description 针对表【orders(订单表)】的数据库操作Mapper
* @createDate 2025-07-22 13:24:24
* @Entity com.sky.entity.Orders
*/
public interface OrdersMapper extends BaseMapper<Orders> {
    /**
     * 插入订单数据
     * @param orders
     * @return
     */
    void saveOrder(Orders orders);
    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    Integer updateOrder(Orders orders);
    /**
     * 根据订单id或订单状态查询订单详情
     * @param orders
     * @return
     */
    List<OrderDetailVO> getOrderDetail(Orders orders);
    /**
     * 根据订单id查询订单信息
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    Orders getOrderById(Long id);

    /**
     * 根据订单条件查询订单数据
     * @param ordersPageQueryDTO
     * @return
     */
    List<OrderVO> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO);
    /**
     * 根据订单状态查询各个状态的订单数量统计
     * @param status
     * @return
     */

    Integer countByStatus(Integer status);

    /**
     * 根据订单状态和下单时间查询订单数据
     * @param status
     * @param orderTime
     * @return
     */
    @Select("select * from orders where status = #{status} and order_time < #{orderTime};")
    List<Orders> getByStatusAndOrderTimeLT(Integer status, LocalDateTime orderTime);

    Integer updateBatchOrder(@Param("ordersList") List<Orders> ordersList);

    /**
     * 营业额统计
     * @param map
     * @return
     */
    @MapKey("everyday")
    List<Map<String, Object>> countTurnoverStatistics(Map<String, Object> map);

    /**
     * 销量排名top10
     * @param map
     * @return
     */
    @MapKey("totalSales")
    List<Map<String, Object>> getSalesTop10(Map<String, Object> map);

    /**
     * 根据条件获取每日订单数
     * @param map
     * @return
     */
    @MapKey("orderCount")
    List<Map<String, Object>> countOrderStatistics(Map<String, Object> map);

}




